package 数组练习题;

import java.util.Scanner;

/*公司年会有一个寻找锦鲤的游戏，每一个员工随意写一个字，如果在“锦鲤”词库中有这个字，那么就奖励500元锦鲤
红包，否则就没有，每人只能玩一次。*/
public class Demo12 {
    public static void main(String[] args) {
        char[] koiFishWords = {'一','今','地','定','年','开','我','果','火','爱','结','花','遍'};
        Scanner scanner=new Scanner(System.in);
        System.out.print("请输入一个字：");
        char a=scanner.next().charAt(0);
        int index=-1;
        for (int left=0,right=koiFishWords.length-1;left<right;){
            int mid=left+(right-left)/2;
            if(a==koiFishWords[left]){
              index=mid;
              break;
            }else if(a>koiFishWords[mid]){
                left=mid+1;
            }else {
                right=mid-1;
            }

        }
        if (index!=-1){
            System.out.println("恭喜您获得了500元");
        }else {
            System.out.println("很遗憾没有获得奖励");
        }
       /* boolean flag=false;
        for (int i = 0; i < koiFishWords.length; i++){
            if (a==koiFishWords[i]){
             flag=true;
            }
        }
        if (flag){
            System.out.println("恭喜您获得了500元");
        }else {
            System.out.println("很遗憾没有获得奖励");
        }*/
    }
}
